package com.sxm.yiwei.tools;

import android.util.Log;

import com.sxm.yiwei.utils.SPopupWindow;

import java.text.SimpleDateFormat;

/**
 * Created by KuKa on 2017/9/28.
 * 获取当前时间 自动添加十分钟后 年月日时分秒随之变化(跑腿 急件的当前时间)
 */

public class SendBookTime {


    private Integer iyear;
    private Integer imonth;
    private Integer iday;
    private Integer ihour;
    private Integer iminte;
    private Integer imiao;
    private Integer newNumber;
    private int d;
    private String time;
    String tTime = null;
    public String getTime(Long l){
        SimpleDateFormat df1 = new SimpleDateFormat("yyyy");
        SimpleDateFormat df2 = new SimpleDateFormat("MM");
        SimpleDateFormat df3 = new SimpleDateFormat("dd");
        SimpleDateFormat df4 = new SimpleDateFormat("HH");
        SimpleDateFormat df5 = new SimpleDateFormat("mm");
        SimpleDateFormat df6 = new SimpleDateFormat("ss");
        //年
        iyear = Integer.valueOf(df1.format(l));
        //月
        imonth = Integer.valueOf(df2.format(l));
        // 日
        iday = Integer.valueOf(df3.format(l));
        // 时
        ihour = Integer.valueOf(df4.format(l));
        //分
        iminte = Integer.valueOf(df5.format(l));
        imiao = Integer.valueOf(df6.format(l));
        newNumber = iday;
        int nowday = iday;
        int i = iminte + 10;
        if (i>59){// 分
            i = i-59;
            ihour = ihour +1;
        }else {
            i = iminte +10;
        }
        if (ihour >24){//时
            ihour = ihour -24;
            iday = iday +1;
        }else {

        }

        int[] oneMonth = new int[]{1,3,5,7,8,10,12};
        int[] twoMonth = new int[]{4,6,9,11};


        if (iday >nowday){ // 天
            d = iday - nowday;

        }else {}
        if (SPopupWindow.monthLoop(oneMonth, imonth)){
            if (iday >31){
                newNumber = iday -31;
                imonth = imonth +1;
                if (imonth >12){
                    iday =1;
                    imonth =1;
                    iyear = iyear +1;

                }else {}
            }else {

            }
        }else if (SPopupWindow.monthLoop(twoMonth, imonth)){
            if (iday >30){
                newNumber = iday -30;
                imonth = imonth +1;
                if (imonth >12){
                    iday =1;
                    imonth =1;
                    iyear = iyear +1;

                }else {}
            }else {

            }
        }else {
            if (iday >28){
                newNumber = iday -28;
                imonth = imonth +1;
                if (imonth >12){
                    iday =1;
                    imonth =1;
                    iyear = iyear +1;

                }else {}
            }else {

            }
        }

        switch (d){
            case 0:
               tTime="今天 "+ihour+"点 "+i+"分";
                break;
            case 1:
               tTime="明天 "+ihour+"点 "+i+"分";
                break;
        }
        time = iyear +"-"+ imonth +"-"+ newNumber +" "+ (ihour) +":"+ i+":"+ imiao;

        String result = time+"/"+tTime;
        return result;
    }

}
